package com.jcl.recruit.elasticsearch.resume.logic;

import com.alibaba.fastjson.JSONObject;
import com.jcl.core.constants.ChannelSourceConstant;
import com.jcl.core.utils.ChannelUtils;
import com.jcl.core.utils.CollectionUtils;
import com.jcl.recruit.elasticsearch.core.constants.ResumeConstant;
import com.jcl.recruit.elasticsearch.resume.model.ResumeExternalMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName ResumeCrawlerExportLogic
 * @Author yyliu
 * @Date 2018/11/13 10:20
 * @Version 1.0
 **/
@Component
public class ResumeDownloadLogic {

    @Autowired
    private SearchResumeBasicInfoLogic searchResumeBasicInfoLogic;

    @Autowired
    private ResumeExternalMsgLogic resumeExternalMsgLogic;

    public ResumeExternalMsg getExternalMsg(Integer resumeId) {

        List<ResumeExternalMsg> list = resumeExternalMsgLogic.findListByResumeId(resumeId,
                ResumeConstant.RESUME_EXTERNAL_TYPE_SEARCH);
        if (CollectionUtils.isNotEmpty(list)) {
            return list.get(0);
        }

        return null;
    }


    public Map<String, Object> createDownloadMap(String tenantId,
                                                 String corpCode,
                                                 ResumeExternalMsg resumeExternalMsg) {
        Map<String, Object> data = new HashMap<>();
        data.put("taskType", "buy-resume");
        String _externalMsg = ChannelUtils.decodeResumeExternalMsg(resumeExternalMsg.getContext());
        data.put("buyResumeContext", JSONObject.parse(_externalMsg));
        data.put("siteCode", ChannelSourceConstant.crawlerSourceMap.get(resumeExternalMsg.getSource()));
        data.put("corpCode", corpCode);
        data.put("tenantId", tenantId);
        return data;
    }


}
